﻿// <copyright file="FindChild.xaml.cs" company="company"> 
// (C) 2010 . All rights reserved
// </copyright>
// <author>Lukasz Bartczak</author>

namespace SecretaryAppNav.Views
{
    using System;
    using System.Windows;
    using System.Windows.Controls;
    using SecretaryAppNav.ClientWcfService;
    using Telerik.Windows.Controls;

    /// <summary>
    /// FindChild partial class
    /// </summary>
    public partial class FindChild : Page
    {
        /// <summary>
        /// Service proxy
        /// </summary>
        private Service1Client client = new Service1Client();

        /// <summary>
        /// Initializes a new instance of the <see cref="FindChild"/> class.
        /// </summary>
        public FindChild()
        {
            InitializeComponent();

            this.client.GetChildAndOpiekunByFirstnameLastnameCompleted += new EventHandler<GetChildAndOpiekunByFirstnameLastnameCompletedEventArgs>(this.Client_GetChildAndOpiekunByFirstnameLastnameCompleted);
            this.client.GetPeymentsByChildAndOpiekunCompleted += new EventHandler<GetPeymentsByChildAndOpiekunCompletedEventArgs>(this.Client_GetPeymentsByChildAndOpiekunCompleted);
        }

        #region Completed method

        /// <summary>
        /// Handles the GetPeymentsByChildAndOpiekunCompleted event of the Client control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="SecretaryAppNav.ClientWcfService.GetPeymentsByChildAndOpiekunCompletedEventArgs"/> instance containing the event data.</param>
        private void Client_GetPeymentsByChildAndOpiekunCompleted(object sender, GetPeymentsByChildAndOpiekunCompletedEventArgs e)
        {
            this.gridViewDataControl2.ItemsSource = (e.Result != null) ? e.Result : null;
        }

        /// <summary>
        /// Handles the GetChildAndOpiekunByFirstnameLastnameCompleted event of the Client control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="SecretaryAppNav.ClientWcfService.GetChildAndOpiekunByFirstnameLastnameCompletedEventArgs"/> instance containing the event data.</param>
        private void Client_GetChildAndOpiekunByFirstnameLastnameCompleted(object sender, GetChildAndOpiekunByFirstnameLastnameCompletedEventArgs e)
        {
            this.gridViewDataControl1.ItemsSource = e.Result;
        }

        #endregion
        /// <summary>
        /// Handles the Click event of the button1 control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void Button1_Click(object sender, RoutedEventArgs e)
        {
            this.client.GetChildAndOpiekunByFirstnameLastnameAsync(this.tbChildName.Value.ToString(), this.tbChildSurname.Value.ToString());
        }

        /// <summary>
        /// Handles the SelectionChanged event of the GridViewDataControl1 control - Show payment of selected child.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Telerik.Windows.Controls.SelectionChangeEventArgs"/> instance containing the event data.</param>
        private void GridViewDataControl1_SelectionChanged(object sender, SelectionChangeEventArgs e)
        {
            DzieckoAndOpiekun selectedRow = (DzieckoAndOpiekun)this.gridViewDataControl1.SelectedItems[0];
            this.client.GetPeymentsByChildAndOpiekunAsync(selectedRow.dzieckoImie, selectedRow.dzieckoNazwisko, selectedRow.opiekunImie, selectedRow.opiekunNazwisko);
        }
    }
}
